/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Domain;

import Data.DBAccess;
import java.sql.SQLException;
import java.util.Scanner;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author JoanIsaac
 */
public class CBDE {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {

        Scanner myScanner = new Scanner(System.in);
        Boolean b = true;
        while(b) {
            System.out.println("OPCION 1: INSERT EN TABLAS BORRADO CONTENIDO ANTERIOR");
            System.out.println("OPCION 2: INSERT EN TABLAS SIN BORRADO DEL CONTENIDO");
            System.out.println("OPCION 3: EJECUTAR QUERYS");
            System.out.println("OPCION 4: FINALIZAR SCRIPT");
            int i = myScanner.nextInt();
            switch (i) {
                case 1 :
                    insertInOracle(true);
                    break;
                case 2 :
                    insertInOracle(false);
                    break;
                case 3 :
                    executeQuerys();
                    break;
                case 4 :
                    b = false;
                default :
                    break;
            }
        
        }
            //TIRAR 5 VECES LAS QUERYS Y MIRAR TIEMPO MINIMO
    }
    
    private static void insertInOracle(boolean truncate) {
        OracleWorkFlow o = OracleWorkFlow.getInstance();
       if(truncate)
            o.TruncateAll();
        long tiempoInicio = System.currentTimeMillis();
        Integer counter = 0;
        System.out.println("    INSERTANDO EN REGION");
        counter += o.InsertRegion(truncate);
        System.out.println("    INSERTANDO EN NATION");
        counter += o.InsertNation(truncate);
        System.out.println("    INSERTANDO EN CUSTOMER");
        counter += o.insertIntoCustomer(truncate);
        System.out.println("    INSERTANDO EN ORDERS");
        counter += o.insertOrders(truncate);
        System.out.println("    INSERTANDO EN PARTS");
        counter += o.insertParts(truncate);
        System.out.println("    INSERTANDO EN SUPPLIERS");
        counter += o.insertSuppliers(truncate);
        System.out.println("    INSERTANDO EN PARTSUPP");
        counter += o.insertPartSupp(truncate);
        System.out.println("    INSERTANDO EN LINEITEM");
        counter += o.inserLineItem(truncate);
        long totaltime = System.currentTimeMillis()-tiempoInicio;
        System.out.println("TIEMPO DE INSERCIONES : "+totaltime/1000+"s");
    }
    private static void executeQuerys() {

        OracleWorkFlow o = OracleWorkFlow.getInstance();
        long time1 = o.executeQuery1(5);
        System.out.println("QUERY1 = "+time1+"ms");
        long time2 = o.executeQuery2(5);
        System.out.println("QUERY2 = "+time2+"ms");
        long time3 = o.executeQuery3(5);
        System.out.println("QUERY3 = "+time3+"ms");
        long time4 = o.executeQuery4(5);
        System.out.println("QUERY4 = "+time4+"ms");
    }
}
